package com.wind.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.wind.entity.Announcement;
import com.wind.entity.Article;
import com.wind.service.IAnnouncementService;
import com.wind.vo.ResultData;
import com.wind.vo.ResultDataGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * Created by Administrator on 2021/5/23.
 */
@Api(tags = "活动公告相关接口")
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Resource
    IAnnouncementService announcementService;
    @ApiOperation("所有活动公告")
    @GetMapping("/list")
    public ResultData<List<Announcement>> listAll(){
        Wrapper<Announcement> wrapper = new EntityWrapper<>();
        wrapper.eq("is_active",1);
        wrapper.orderBy("create_time",false);
        List<Announcement> list = announcementService.selectList(wrapper);
        return ResultDataGenerator.genSuccessResult(list, "查询成功");
    }
    @ApiOperation("查询指定活动公告")
    @GetMapping("/view/{id}")
    public ResultData<Announcement> selectByid(@PathVariable("id") Long id){
        Wrapper<Announcement>  wrapper = new EntityWrapper<>();
        wrapper.eq("id",id);
        wrapper.eq("is_active",1);
        Announcement announcement = announcementService.selectOne(wrapper);
        if(Objects.isNull(announcement)){
            return ResultDataGenerator.genFailResult(null,"公告不存在");
        }
        return ResultDataGenerator.genSuccessResult(announcement,"查询成功");
    }
}
